#!/bin/bash

# This file is licensed under GPLv3, see https://www.gnu.org/licenses/

if [[ ! "$(grep foobz1 PKGBUILD)" ]]  && [[ ! "$(grep foobz2 PKGBUILD)" ]] ; then
	for line in $(grep "^prepare_.\+()" PKGBUILD -o) ; do
		echo -e "$line {\n echo \"foo_$line\"\n }" >> PKGBUILD
	done
	for line in $(grep "^package_.\+()" PKGBUILD -o) ; do
		echo -e "$line {\n echo \"foo_$line\"\n }" >> PKGBUILD
	done

source ./PKGBUILD
	echo '

prepare() {
	echo "======= Fake prepare() ======="
	echo "foobz2"
}

build() {
	echo "======= Fake build() ======="
	echo "foobz3"
}

check() {
	echo "======= Fake build() ======="
	echo "foobz3"
}
' >> ./PKGBUILD

# shellcheck disable=SC2154
if [ "${#pkgname[@]}" -eq 1 ] ; then
		echo "
package() {
	echo '======= Fake package() ======='
	echo 'foobz1'
}
	" >> ./PKGBUILD
else
	# shellcheck disable=SC2154
	for _pkg_name in "${pkgname[@]}" ; do
		echo "
package_${_pkg_name}() {
	echo '======= Fake package() ======='
	echo 'foobz1'
}
	" >> ./PKGBUILD
	done
fi

fi
# shellcheck disable=SC2068
/usr/bin/makepkg --skippgpcheck $@
